package com.testDemo.hutool;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ReUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.testDemo.bean.A;
import com.testDemo.bean.A2;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author: zouren
 * @date: 2020/8/18 10:32
 * @description:
 */
public class ReUtilTest {
    @Test
    public void get(){
        // 示例字符串
        String input1 = "feat(A12as 34): 增加了新功能";
        String input2 = "fix( 在567sd 8): 修复了登录问题";
        String input23 = "afix( 在567sd 8): 修复了登录问题";
        String regex = "^(feat|fix)\\((.+)\\):\\s.*";

        System.out.println( ReUtil.get(regex, input1, 1));

        System.out.println( ReUtil.get(regex, input1, 2));
        System.out.println( ReUtil.get(regex, input2, 1));
        System.out.println( ReUtil.get(regex, input2, 2));

        System.out.println( ReUtil.get(regex, input23, 1));
        System.out.println( ReUtil.get(regex, input23, 2));


    }
    @Test
    public void test222(){


        String input1 = "bb\"test1\"aaa";
        extractMixedContent(input1);
    }
    public static List<String> extractMixedContent(String input) {
        List<String> result = new ArrayList<>();
        // 正则表达式匹配双引号内容和非双引号内容
        Pattern pattern = Pattern.compile("\"([^\"]*)\"|([^\"]+)");
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            if (matcher.group(1) != null) {  // 双引号内容
                result.add(matcher.group(1));
                System.out.println("双引号内容："+matcher.group(1));
            } else if (matcher.group(2) != null) {  // 非双引号内容
                result.add(matcher.group(2));
                System.out.println("内容："+matcher.group(2));

            }
        }
        return result;
    }
}
